# 为RegistryKey对象编写错误
Get-ChildItem | ForEach-Object {
    if($_.GetType().ToString() -eq "Microsoft.Win32.RegistryKey"){
        Write-Error "Invalid object" -ErrorId B1 -TargetObject $_
    }else{
        $_
    }
}

# 将错误信息写入控制台
Write-Error "Access denied."

# 将错误写入控制台并指定类别
Write-Error -Message "Error: Too many input values." -Category InvalidArgument

# 使用Exception对象写入错误
$E = [System.Exception]@{Source = "Get-ParameterNames.ps1";HelpLink="https://go.microsoft.com/fwlink/?LinkID=113425"}
Write-Error -Exception $E -Message "Files not found. The $Files location does not contain any XML files."

# 这里要背诵，一些-Category后面的值

# 还有Write-Error 的属性
